package com.appwoo.txtws.activity;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CursorAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.appwoo.txtws.adapter.ContactAdapter;
import com.appwoo.txtws.bean.ContactInfo;
import com.appwoo.txtws.component.Logger;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ContactListViewActivity extends Activity
{
  private static final int DIALOG_KEY = 0;
  private static final int PHONES_CONTACT_ID_INDEX = 3;
  private static final int PHONES_DISPLAY_NAME_INDEX = 0;
  private static final int PHONES_NUMBER_INDEX = 1;
  private static final int PHONES_PHOTO_ID_INDEX = 2;
  private static final String[] PHONES_PROJECTION = { "display_name", "data1", "photo_id", "contact_id" };
  protected String[] autoContact = null;
  private View.OnClickListener btnClick = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      switch (paramAnonymousView.getId())
      {
      default:
        return;
      case 2131493056:
        Logger.i("eoe", ContactListViewActivity.this.numberStr);
        Intent localIntent = ContactListViewActivity.this.getIntent();
        Bundle localBundle = new Bundle();
        String str1 = ContactListViewActivity.this.numberStr;
        String str2 = ContactListViewActivity.this.nameStr;
        if (str1 != "")
          str1 = str1.substring(1);
        if (str2 != "")
          str2 = str2.substring(1);
        localBundle.putString("numberStr", str1);
        localBundle.putString("nameStr", str2);
        localIntent.putExtras(localBundle);
        ContactListViewActivity.this.setResult(-1, localIntent);
        ContactListViewActivity.this.finish();
        return;
      case 2131493057:
      }
      ContactListViewActivity.this.finish();
    }
  };
  protected ContactAdapter ca;
  ArrayList<ContactInfo> contactList = new ArrayList();
  TextView emptytextView;
  ListView listView;
  protected Cursor mCursor = null;
  protected CursorAdapter mCursorAdapter;
  private TextWatcher mTextWatcher = new TextWatcher()
  {
    public void afterTextChanged(Editable paramAnonymousEditable)
    {
    }

    public void beforeTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3)
    {
    }

    public void onTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3)
    {
      String str1 = paramAnonymousCharSequence.toString();
      if (str1.length() >= 13)
      {
        Matcher localMatcher = Pattern.compile("\\(([1][3,5,8]+\\d{9})\\)").matcher(str1);
        if (localMatcher.find())
        {
          String str2 = localMatcher.group(1);
          ContactListViewActivity.this.DealWithAutoComplete(ContactListViewActivity.this.contactList, str2);
          Toast.makeText(ContactListViewActivity.this, ContactListViewActivity.this.getString(2131427608), 1000).show();
          ContactListViewActivity.this.ca.setItemList(ContactListViewActivity.this.contactList);
          ContactListViewActivity.this.ca.notifyDataSetChanged();
        }
      }
    }
  };
  protected String nameStr = "";
  protected String numberStr = "";
  AutoCompleteTextView textView;
  protected String[] wNumStr = null;

  private void DealWithAutoComplete(ArrayList<ContactInfo> paramArrayList, String paramString)
  {
    for (int i = 0; ; i++)
    {
      if (i >= paramArrayList.size())
        return;
      if ((paramString.equals(((ContactInfo)paramArrayList.get(i)).userNumber)) && (!((ContactInfo)paramArrayList.get(i)).isChecked.booleanValue()))
      {
        ((ContactInfo)paramArrayList.get(i)).isChecked = Boolean.valueOf(true);
        this.numberStr = (this.numberStr + "," + paramString);
        this.nameStr = (this.nameStr + "," + ((ContactInfo)paramArrayList.get(i)).getContactName());
        this.textView.setText("");
      }
    }
  }

  private void GetLocalContact()
  {
    Cursor localCursor = getContentResolver().query(Contacts.People.CONTENT_URI, null, null, null, null);
    while (true)
    {
      if (!localCursor.moveToNext())
      {
        localCursor.close();
        return;
      }
      ContactInfo localContactInfo = new ContactInfo();
      localContactInfo.contactName = localCursor.getString(localCursor.getColumnIndex("name"));
      localContactInfo.userNumber = localCursor.getString(localCursor.getColumnIndex("number"));
      localContactInfo.userNumber = GetNumber(localContactInfo.userNumber);
      localContactInfo.isChecked = Boolean.valueOf(false);
      if ((IsUserNumber(localContactInfo.userNumber)) && (!this.contactList.contains(localContactInfo)))
        this.contactList.add(localContactInfo);
    }
  }

  private String GetNotInContactNumber(String[] paramArrayOfString, ArrayList<ContactInfo> paramArrayList)
  {
    String str = "";
    int i = 0;
    if (i >= paramArrayOfString.length)
      return str;
    if (IsUserNumber(paramArrayOfString[i]));
    label113: for (int j = 0; ; j++)
    {
      if (j >= paramArrayList.size());
      while (true)
      {
        if (!paramArrayOfString[i].equals(""))
          str = str + "," + paramArrayOfString[i];
        i++;
        break;
        if (!paramArrayOfString[i].equals(((ContactInfo)paramArrayList.get(j)).userNumber))
          break label113;
        paramArrayOfString[i] = "";
      }
    }
  }

  public static String GetNumber(String paramString)
  {
    if (paramString != null)
    {
      if (paramString.startsWith("+86"))
        paramString = paramString.substring(3);
      while (!paramString.startsWith("86"))
        return paramString;
      return paramString.substring(2);
    }
    return "";
  }

  private void GetSimContact(String paramString)
  {
    try
    {
      Intent localIntent = new Intent();
      localIntent.setData(Uri.parse(paramString));
      Uri localUri = localIntent.getData();
      this.mCursor = getContentResolver().query(localUri, null, null, null, null);
      if (this.mCursor != null)
        while (true)
        {
          if (!this.mCursor.moveToNext())
          {
            this.mCursor.close();
            return;
          }
          ContactInfo localContactInfo = new ContactInfo();
          int i = this.mCursor.getColumnIndex("name");
          localContactInfo.contactName = this.mCursor.getString(i);
          int j = this.mCursor.getColumnIndex("number");
          localContactInfo.userNumber = this.mCursor.getString(j);
          localContactInfo.userNumber = GetNumber(localContactInfo.userNumber);
          localContactInfo.isChecked = Boolean.valueOf(false);
          if ((IsUserNumber(localContactInfo.userNumber)) && (!this.contactList.contains(localContactInfo)))
          {
            if (IsAlreadyCheck(this.wNumStr, localContactInfo.userNumber))
            {
              localContactInfo.isChecked = Boolean.valueOf(true);
              this.numberStr = (this.numberStr + "," + localContactInfo.userNumber);
            }
            this.contactList.add(localContactInfo);
          }
        }
    }
    catch (Exception localException)
    {
      Logger.i("xjf", localException.toString());
    }
  }

  private boolean IsAlreadyCheck(String[] paramArrayOfString, String paramString)
  {
    for (int i = 0; ; i++)
    {
      if (i >= paramArrayOfString.length)
        return false;
      if (paramString.equals(paramArrayOfString[i]))
        return true;
    }
  }

  private boolean IsContain(ArrayList<ContactInfo> paramArrayList, String paramString)
  {
    for (int i = 0; ; i++)
    {
      if (i >= paramArrayList.size())
        return false;
      if (paramString.equals(((ContactInfo)paramArrayList.get(i)).userNumber))
        return true;
    }
  }

  public static boolean IsUserNumber(String paramString)
  {
    int i = paramString.length();
    boolean bool1 = false;
    if (i == 11)
    {
      if (!paramString.startsWith("13"))
        break label26;
      bool1 = true;
    }
    label26: boolean bool2;
    do
    {
      return bool1;
      if (paramString.startsWith("15"))
        return true;
      bool2 = paramString.startsWith("18");
      bool1 = false;
    }
    while (!bool2);
    return true;
  }

  private void getContactsSec()
  {
    Uri localUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    String[] arrayOfString = { "_id", "display_name", "data1" };
    ((String[])null);
    Cursor localCursor = managedQuery(localUri, arrayOfString, null, null, "display_name COLLATE LOCALIZED ASC");
    while (true)
    {
      if (!localCursor.moveToNext())
      {
        localCursor.close();
        return;
      }
      ContactInfo localContactInfo = new ContactInfo();
      String str1 = localCursor.getString(localCursor.getColumnIndex("display_name"));
      String str2 = localCursor.getString(localCursor.getColumnIndex("data1"));
      localContactInfo.contactName = str1;
      localContactInfo.userNumber = str2;
      localContactInfo.userNumber = GetNumber(localContactInfo.userNumber);
      localContactInfo.isChecked = Boolean.valueOf(false);
      if ((IsUserNumber(localContactInfo.userNumber)) && (!IsContain(this.contactList, localContactInfo.userNumber)))
      {
        if (IsAlreadyCheck(this.wNumStr, localContactInfo.userNumber))
        {
          localContactInfo.isChecked = Boolean.valueOf(true);
          this.numberStr = (this.numberStr + "," + localContactInfo.userNumber);
        }
        this.contactList.add(localContactInfo);
      }
    }
  }

  private void getPhoneContacts(Context paramContext)
  {
    Cursor localCursor = paramContext.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PHONES_PROJECTION, null, null, null);
    if (localCursor != null);
    while (true)
    {
      if (!localCursor.moveToNext())
      {
        localCursor.close();
        return;
      }
      String str1 = localCursor.getString(1);
      if (!TextUtils.isEmpty(str1))
      {
        String str2 = localCursor.getString(0);
        Long.valueOf(localCursor.getLong(3));
        Long.valueOf(localCursor.getLong(2));
        ContactInfo localContactInfo = new ContactInfo();
        localContactInfo.contactName = str2;
        localContactInfo.userNumber = str1;
        localContactInfo.userNumber = GetNumber(localContactInfo.userNumber);
        localContactInfo.isChecked = Boolean.valueOf(false);
        if ((IsUserNumber(localContactInfo.userNumber)) && (!IsContain(this.contactList, localContactInfo.userNumber)))
        {
          if (IsAlreadyCheck(this.wNumStr, localContactInfo.userNumber))
          {
            localContactInfo.isChecked = Boolean.valueOf(true);
            this.numberStr = (this.numberStr + "," + localContactInfo.userNumber);
          }
          this.contactList.add(localContactInfo);
        }
      }
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903077);
    this.listView = ((ListView)findViewById(2131493059));
    this.textView = ((AutoCompleteTextView)findViewById(2131493054));
    this.emptytextView = ((TextView)findViewById(2131493058));
    Button localButton1 = (Button)findViewById(2131493056);
    Button localButton2 = (Button)findViewById(2131493057);
    this.emptytextView.setVisibility(8);
    this.wNumStr = getIntent().getExtras().getString("wNumberStr").replace("，", ",").split(",");
    new GetContactTask(null).execute(new String[] { "" });
    this.listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
      public void onItemClick(AdapterView paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
      {
        CheckBox localCheckBox = (CheckBox)((LinearLayout)paramAnonymousView).getChildAt(0).findViewById(2131493045);
        if (localCheckBox.isChecked())
        {
          localCheckBox.setChecked(false);
          ContactListViewActivity.this.numberStr = ContactListViewActivity.this.numberStr.replace("," + ((ContactInfo)ContactListViewActivity.this.contactList.get(paramAnonymousInt)).getUserNumber(), "");
          ContactListViewActivity.this.nameStr = ContactListViewActivity.this.nameStr.replace("," + ((ContactInfo)ContactListViewActivity.this.contactList.get(paramAnonymousInt)).getContactName(), "");
          ((ContactInfo)ContactListViewActivity.this.contactList.get(paramAnonymousInt)).isChecked = Boolean.valueOf(false);
          return;
        }
        localCheckBox.setChecked(true);
        ContactListViewActivity localContactListViewActivity1 = ContactListViewActivity.this;
        localContactListViewActivity1.numberStr = (localContactListViewActivity1.numberStr + "," + ((ContactInfo)ContactListViewActivity.this.contactList.get(paramAnonymousInt)).getUserNumber());
        ContactListViewActivity localContactListViewActivity2 = ContactListViewActivity.this;
        localContactListViewActivity2.nameStr = (localContactListViewActivity2.nameStr + "," + ((ContactInfo)ContactListViewActivity.this.contactList.get(paramAnonymousInt)).getContactName());
        ((ContactInfo)ContactListViewActivity.this.contactList.get(paramAnonymousInt)).isChecked = Boolean.valueOf(true);
      }
    });
    localButton1.setOnClickListener(this.btnClick);
    localButton2.setOnClickListener(this.btnClick);
  }

  protected Dialog onCreateDialog(int paramInt)
  {
    switch (paramInt)
    {
    default:
      return null;
    case 0:
    }
    ProgressDialog localProgressDialog = new ProgressDialog(this);
    localProgressDialog.setMessage(getString(2131427609));
    localProgressDialog.setIndeterminate(true);
    localProgressDialog.setCancelable(true);
    return localProgressDialog;
  }

  private class GetContactTask extends AsyncTask<String, String, String>
  {
    private GetContactTask()
    {
    }

    public String doInBackground(String[] paramArrayOfString)
    {
      ContactListViewActivity.this.getPhoneContacts(ContactListViewActivity.this);
      ContactListViewActivity.this.GetSimContact("content://icc/adn");
      ContactListViewActivity.this.GetSimContact("content://sim/adn");
      return "";
    }

    public void onPostExecute(String paramString)
    {
      if (ContactListViewActivity.this.contactList.size() == 0)
      {
        ContactListViewActivity.this.emptytextView.setVisibility(0);
        ContactListViewActivity.this.removeDialog(0);
        return;
      }
      ContactListViewActivity.Mycomparator localMycomparator = new ContactListViewActivity.Mycomparator(ContactListViewActivity.this);
      Collections.sort(ContactListViewActivity.this.contactList, localMycomparator);
      ContactListViewActivity.this.numberStr = (ContactListViewActivity.this.GetNotInContactNumber(ContactListViewActivity.this.wNumStr, ContactListViewActivity.this.contactList) + ContactListViewActivity.this.numberStr);
      ContactListViewActivity.this.ca = new ContactAdapter(ContactListViewActivity.this, ContactListViewActivity.this.contactList);
      ContactListViewActivity.this.listView.setAdapter(ContactListViewActivity.this.ca);
      ContactListViewActivity.this.listView.setTextFilterEnabled(true);
      ContactListViewActivity.this.autoContact = new String[ContactListViewActivity.this.contactList.size()];
      for (int i = 0; ; i++)
      {
        if (i >= ContactListViewActivity.this.contactList.size())
        {
          ArrayAdapter localArrayAdapter = new ArrayAdapter(ContactListViewActivity.this, 17367050, ContactListViewActivity.this.autoContact);
          ContactListViewActivity.this.textView.setAdapter(localArrayAdapter);
          ContactListViewActivity.this.textView.addTextChangedListener(ContactListViewActivity.this.mTextWatcher);
          break;
        }
        ContactListViewActivity.this.autoContact[i] = (((ContactInfo)ContactListViewActivity.this.contactList.get(i)).contactName + "(" + ((ContactInfo)ContactListViewActivity.this.contactList.get(i)).userNumber + ")");
      }
    }

    protected void onPreExecute()
    {
      ContactListViewActivity.this.showDialog(0);
    }
  }

  public class Mycomparator
    implements Comparator
  {
    public Mycomparator()
    {
    }

    public int compare(Object paramObject1, Object paramObject2)
    {
      ContactInfo localContactInfo1 = (ContactInfo)paramObject1;
      ContactInfo localContactInfo2 = (ContactInfo)paramObject2;
      return Collator.getInstance(Locale.CHINA).compare(localContactInfo1.contactName, localContactInfo2.contactName);
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.ContactListViewActivity
 * JD-Core Version:    0.6.2
 */